#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
using namespace std;
int n = 0;
vector<int> v(1, 0);
int count = 0;
void recursion(int l, vector<bool> dp, string s)
{
    //cout<<"n="<<n<<",l="<<l<<endl;
    //cout<<(string)s<<endl;
    for (int i = 1;i < v.size();i++)
    {
        if (dp[i] == true || dp[v[i]] == true) continue;
        vector<bool> dpc = dp;
        dpc[i] = true;
        string sc = s;
        sc.push_back('A' + i - 1);
        if (l == n) ++count;
        else recursion(l + 1, dpc, sc);
    }
    //cout<<count<<endl;
    return;
}
int main()
{
    cin >> n;
    for (int i = 1;i < n + 1;i++)
    {
        int tmp = 0;
        cin >> tmp;
        v.push_back(tmp);
    }
    vector<bool> dp(n + 1, false);
    string s;
    recursion(1, dp, s);
    cout << count << endl;
    return 0;
}